var e = n(require("../../libs/mini/create")), t = n(require("../../store/index")), i = require("../../api/wifi");

function n(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

var a = getApp(), o = null;

e.default.Page(t.default, {
    use: [ "customLoading", "custom", "userInfo" ],
    data: {
        loading: !0,
        showAction: !1,
        actions: [],
        form: {
            role: 0,
            role_name: "",
            percent: 80
        },
        showMiniPopup: !1
    },
    _initAd: function() {
        var e = this.data.$.custom;
        wx.createInterstitialAd && 1 == e.ad_screen_active && (o = wx.createInterstitialAd({
            adUnitId: e.ad_screen || ""
        })).onError(function(e) {
            console.error("插屏广告加载失败：", e);
        });
    },
    onShow: function() {
        var e = this.data.$.custom;
        setTimeout(function() {
            o && 1 == e.ad_screen_active && o.show().catch(function(e) {
                console.error("插屏广告加载失败：", e);
            });
        }, 1e3 * e.ad_screen_timeout);
    },
    showLoading: function() {
        var e = 0 < arguments.length && void 0 !== arguments[0] ? arguments[0] : "", t = !(1 < arguments.length && void 0 !== arguments[1]) || arguments[1];
        this.setData({
            loading: !0
        }), wx.showLoading({
            title: e,
            mask: t
        });
    },
    hideLoading: function() {
        this.setData({
            loading: !1
        }), wx.hideLoading();
    },
    handleBannerItemClick: function(e) {
        var t = e.currentTarget.dataset.item;
        switch (t.type) {
          case "h5":
            t.url ? wx.navigateTo({
                url: "/pages/webview/index?src=" + t.url
            }) : a.utils.modalText("未设置跳转内容，操作失败");
            break;

          case "mini":
            wx.navigateToMiniProgram({
                appId: t.appid,
                path: decodeURIComponent(t.url),
                fail: function(e) {
                    "navigateToMiniProgram:fail invalid appid" === (e = e.errMsg) ? a.utils.modalText("跳转失败，可能是小程序路径或appid填写错误") : "navigateToMiniProgram:fail can't navigate to myself" === e && wx.navigateTo({
                        url: decodeURIComponent(t.url)
                    });
                }
            });
        }
    },
    onActionShow: function() {
        var e = this.data.$.userInfo;
        1 == e.role ? this.setData({
            actions: [ {
                id: 2,
                name: "拓展员",
                className: "width100"
            }, {
                id: 3,
                name: "商家",
                className: "width100"
            } ],
            showAction: !0
        }) : 2 == e.role && this.setData({
            actions: [ {
                id: 3,
                name: "商家",
                className: "width100"
            } ],
            showAction: !0
        });
    },
    onActionClose: function() {
        this.setData({
            showAction: !1
        });
    },
    _setForm: function(e, t) {
        this.setData(function(e, t, i) {
            return t in e ? Object.defineProperty(e, t, {
                value: i,
                enumerable: !0,
                configurable: !0,
                writable: !0
            }) : e[t] = i, e;
        }({}, "form." + e, t));
    },
    onInviteSelect: function(e) {
        e = (t = e.detail).id;
        var t = t.name;
        this._setForm("role", e), this._setForm("role_name", t);
    },
    handleCloseMiniPopup: function() {
        this.setData({
            showMiniPopup: !1
        });
    },
    handleShowMiniPopup: function() {
        this.setData({
            showMiniPopup: !0
        });
    },
    handleGenerateBindCode: function() {
        var e = this, n = this.data.$.userInfo;
        if (!n.openid) return a.utils.toastText("未登录！");
        var o = Object.assign({}, this.data.form);
        if (!o.role || !o.role_name) return a.utils.toastText("请选择邀请类型");
        this.showLoading(), o.openid = n.openid, (0, i.getBindCode)(o).then(function(i) {
            e.hideLoading(), a.utils.toastText("", "success"), setTimeout(function() {
                t.default.setTempData(i), wx.redirectTo({
                    url: "/pages/status/index"
                });
            }, 300);
        }).catch(function(t) {
            e.hideLoading();
        });
    },
    handleViewMyTeam: function() {
        wx.navigateTo({
            url: "/pages/member/index"
        });
    },
    onPercentChange: function(e) {
        e = e.detail, this.setData({
            "form.percent": e
        });
    }
});